package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.YtOuterTubePass;
import com.ruoyi.system.service.IYtOuterTubePassService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 外管证Controller
 * 
 * @author magichaohao
 * @date 2021-05-19
 */
@Controller
@RequestMapping("/system/pass")
public class YtOuterTubePassController extends BaseController
{
    private String prefix = "system/pass";

    @Autowired
    private IYtOuterTubePassService ytOuterTubePassService;

    @RequiresPermissions("system:pass:view")
    @GetMapping()
    public String pass()
    {
        return prefix + "/pass";
    }

    /**
     * 查询外管证列表
     */
    @RequiresPermissions("system:pass:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(YtOuterTubePass ytOuterTubePass)
    {
        startPage();
        List<YtOuterTubePass> list = ytOuterTubePassService.selectYtOuterTubePassList(ytOuterTubePass);
        return getDataTable(list);
    }

    /**
     * 导出外管证列表
     */
    @RequiresPermissions("system:pass:export")
    @Log(title = "外管证", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(YtOuterTubePass ytOuterTubePass)
    {
        List<YtOuterTubePass> list = ytOuterTubePassService.selectYtOuterTubePassList(ytOuterTubePass);
        ExcelUtil<YtOuterTubePass> util = new ExcelUtil<YtOuterTubePass>(YtOuterTubePass.class);
        return util.exportExcel(list, "外管证数据");
    }

    /**
     * 新增外管证
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存外管证
     */
    @RequiresPermissions("system:pass:add")
    @Log(title = "外管证", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(YtOuterTubePass ytOuterTubePass)
    {
        return toAjax(ytOuterTubePassService.insertYtOuterTubePass(ytOuterTubePass));
    }

    /**
     * 修改外管证
     */
    @GetMapping("/edit/{outerTubePassId}")
    public String edit(@PathVariable("outerTubePassId") Long outerTubePassId, ModelMap mmap)
    {
        YtOuterTubePass ytOuterTubePass = ytOuterTubePassService.selectYtOuterTubePassById(outerTubePassId);
        mmap.put("ytOuterTubePass", ytOuterTubePass);
        return prefix + "/edit";
    }

    /**
     * 修改保存外管证
     */
    @RequiresPermissions("system:pass:edit")
    @Log(title = "外管证", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(YtOuterTubePass ytOuterTubePass)
    {
        return toAjax(ytOuterTubePassService.updateYtOuterTubePass(ytOuterTubePass));
    }

    /**
     * 删除外管证
     */
    @RequiresPermissions("system:pass:remove")
    @Log(title = "外管证", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ytOuterTubePassService.deleteYtOuterTubePassByIds(ids));
    }
}
